package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JPanel;

import model.CiiBay;

/**
 * Zorgt voor het laten zien van de banner.
 * @author Marvin
 * @author Yasper
 * @since v1.0
 *
 */



@SuppressWarnings("serial")
public class Banner extends JPanel implements Observer {
	
	private JButton login, registreer;
	private JPanel logPanel;
	private CiiBay ciiBay;
	
	public Banner(CiiBay ciiBay){
		ciiBay.addObserver(this);
		setLayout(new BorderLayout());
		logPanel = new JPanel(new GridLayout(2,1));
		login = new JButton("Login");
		registreer = new JButton("Registreer");
		registreer.setBackground(Color.orange);
		login.setBackground(Color.ORANGE);
		logPanel.setBackground(Color.ORANGE);
		add(new BannerBackground(),BorderLayout.CENTER);
		add(logPanel, BorderLayout.EAST);
		logPanel.add(login);
		logPanel.add(registreer);
		this.ciiBay = ciiBay;
		registreer.addActionListener(new KnopHandler());
		login.addActionListener(new KnopHandler());

	}
	
	class KnopHandler implements ActionListener{
		/**
		 * De event handler voor de banner. Roept in cii-bay de methode aan om de view te veranderen.
		 * @author Yasper
		 * @author Jaap
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == registreer){
				ciiBay.veranderView("registreer");
			}
			if(e.getSource() == login){
				if(login.getText().equals("Login")){
				ciiBay.veranderView("login");
				}
				else{
					ciiBay.logOut();
				}
			}
		}
	}
	
	@Override
	public void update(Observable arg0, Object arg1) {
		if(ciiBay.getIngelogtPersoon() != null){
		login.setText("Logout");
		logPanel.remove(registreer);
		} 
		else {
			login.setText("Login");
			logPanel.add(registreer);
		}
	}
}
